package org.session.dao.impl;

import javax.ejb.Stateless;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.entity.Patient;
import org.entity.Users;
import org.session.dao.PatientDao;
import org.session.dao.UsersDao;

/**
 * Session Bean implementation class UsersDaoImpl
 */
@SuppressWarnings("unused")
@Stateless
@Local(UsersDao.class)
@Remote(UsersDao.class)
public class UsersDaoImpl implements UsersDao {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public UsersDaoImpl() {
        // TODO Auto-generated constructor stub
    }
	/* (non-Javadoc)
	 * @see org.session.dao.UsersDao#addUsers(org.entity.Users)
	 */
	public void addUsers(Users user) {
		em.persist(user);
	}
	
	/* (non-Javadoc)
	 * @see org.session.dao.UsersDao#login(java.lang.String, java.lang.String)
	 */
	public Users login(String user_id, String password) {
		
			Query query = em.createQuery("select user from Users user where user_id=:user_id and password=:password");
            query.setParameter("user_id", user_id);  
            query.setParameter("password", password); 
            Users user;
            try{
    			user= (Users) query.getSingleResult();
    		}catch(NoResultException e) {
    			return null;
    		}
    		return user;
		}
	}

